package grobit.torrent

public class Sha1DataTest extends GroovyTestCase {

    void testSha1() {
        Sha1Data sha1Data = new Sha1Data('SHA1SHA1SHA1SHA1SHA1'.bytes)
        assert sha1Data.asString() == 'SHA1SHA1SHA1SHA1SHA1'
        byte[] bytes = sha1Data.getBytes()
        assert bytes.length == 20
        bytes[0] = 'X'
        println sha1Data.asString()
        assert sha1Data.asString() == 'SHA1SHA1SHA1SHA1SHA1'
        sha1Data = new Sha1Data(bytes)
        assert sha1Data.asString() == 'XHA1SHA1SHA1SHA1SHA1'

        assert sha1Data.toString() == 'WEhBMVNIQTFTSEExU0hBMVNIQTE='
    }

    void testBadSha1() {
        shouldFail(AssertionError) {
            new Sha1Data('SHA1'.bytes)
        }
    }

    void testSha1Value() {
        Sha1Data sha1Data = Sha1Data.calculateSha1('The quick brown fox jumps over the lazy cog')
        assert sha1Data.asHexString() == 'de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3'
    }

    void testEquality() {
        Sha1Data sha1Data1 = Sha1Data.calculateSha1('The quick brown fox jumps over the lazy cog')
        Sha1Data sha1Data2 = Sha1Data.calculateSha1('The quick brown fox jumps over the lazy cog')
        assert sha1Data1 == sha1Data2
    }
}
